﻿<form method="post" id="form1">
    @Html.AntiForgeryToken());
    <div class="querybar">
        <table cellpadding="0" cellspacing="1" border="0" width="100%">

            <tr>                <td>                    主题：<input type="text" class="mytext" id="Subject" name="Subject" value="" style="width:260px" />                    发件人：<input type="text" class="mymember" id="SendUser" name="SendUser" value="" unit="0" dept="0" workgroup="0" station="0" user="1" />                    接收时间：<input type="text" class="mycalendar" style="width:90px;" id="Date1" name="Date1" /> 至 <input type="text" style="width:90px;" class="mycalendar" id="Date2" name="Date2" />                    <input type="button" name="Search" onclick="query();" value="&nbsp;&nbsp;查&nbsp;询&nbsp;&nbsp;" class="mybutton" />                    <input type="button" onclick="changeStatus(this); return false;" value="标记为已读" class="mybutton" />                    <input type="button" onclick="del(this); return false;" value="删除所选邮件" class="mybutton" />                </td>            </tr>

        </table>
    </div>    <input type="hidden" name="checkbox_app" id="checkbox_app" value="" />    <table id="listtable"></table>    <div class="buttondiv"></div>
</form>
<script type="text/javascript">
    var appid = '@ViewData["appId"]';
    var iframeid = '@ViewData["tabId"]';
    var dialog = new RoadUI.Window();
    var curPageSize;
    var curPageNumber;
    $(function () {
        $("#listtable").jqGrid({
            url: "QueryInBox?@Html.Raw(ViewData["query"])",
            postData: {
                "__RequestVerificationToken": $("input[name = '__RequestVerificationToken']").val(),
                "appid": appid
            },
            mtype: 'POST',
            datatype: "json",
            colNames: ['主题', '状态', '发件人', '收件时间'],
            colModel: [{
                name: 'Subject',
                index: 'Subject',
                width: 300
            },
                {
                    name: 'IsRead',
                    index: 'IsRead',
                    width: 40
                }, {
                    name: 'SendUserId',
                    index: 'SendUserId',
                    align: "left",
                    width: 120
                }, {
                    name: 'SendDateTime',
                    index: 'SendDateTime',
                    align: "left", width: 80
                }],
            sortname: "SendDateTime",
            sortorder: "desc",
            height: '100%',
            multiselect: true,
            width: $(window).width(),
            loadComplete: function () {
                var gridObj = $("#listtable");
                var records = gridObj.getGridParam("userData");
                curPageSize = records.pagesize;
                curPageNumber = records.pagenumber;
                $(".buttondiv").html(RoadUI.Core.getPager1(records.total, records.pagesize, records.pagenumber, "query"));
            }
        });
    });

    $(window).resize(function () {
        $("#listtable").setGridWidth($(window).width());
    });

    function query(size, number) {
        var data = {
            __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val(),
            Subject: $("#Subject").val(),
            SendUser: $("#SendUser").val(),
            Date1: $("#Date1").val(),
            Date2: $("#Date2").val(),
            pagesize: size,
            pagenumber: number
        };
        $("#listtable").setGridParam({ postData: data }).trigger("reloadGrid");
    }
    function detail(id) {
        window.location = 'ShowMail?@Html.Raw(ViewData["query"])&mailid=' + id + "&pagesize=" + curPageSize + "&pagenumber=" + curPageNumber;
    }
    function changeStatus(but) {
        var rowIds = $("#listtable").jqGrid('getGridParam', 'selarrrow');
        if (rowIds.length == 0) {
            alert("您没有选择要标记的邮件!");
            return false;
        }
        $(but).prop("disabled", true);
        $.ajax({
            url: "ChangeStatus?" + "@Html.Raw(ViewData["query"]));" + " & pagesize=" + curPageSize + " & pagenumber=" + curPageNumber,
            data: {
                "ids": rowIds.join(", "),
                "__RequestVerificationToken": $("input[name = '__RequestVerificationToken']").val()
            },
            type: "post",
            success: function (txt) {
                alert(txt);
                $(but).prop("disabled", false);
                query(curPageSize, curPageNumber);
            }
        });
        return true;
    }
    function del(but) {
        var rowIds = $("#listtable").jqGrid('getGridParam', 'selarrrow'); if (rowIds.length == 0) { alert("您没有选择要删除的邮件!"); return false; } if (!confirm('您真的要删除所选邮件吗?')) { return false; } $(but).prop("disabled", true); $.ajax({
            url: "DeleteMail1 ? " + "@Html.Raw(ViewData["query"])" + " & pagesize=" + curPageSize + " & pagenumber=" + curPageNumber,
            data: {
                "ids": rowIds.join(", "),
                "__RequestVerificationToken": $("input[name = '__RequestVerificationToken']").val()
            },
            type: "post",
            success: function (txt) {
                alert(txt);
                $(but).prop("disabled", false);
                query(curPageSize, curPageNumber);
            }
        });
        return true;
    }
</script>